<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../node_modules/react/umd/react.development.js'></script>
    <script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    <script src='../node_modules/prop-types/prop-types.js'></script>
</head>

<body>
    <div id='root'></div>

    <script type='text/babel'>
        class MyCom extends React.Component {
            constructor(props) {
                super(props)

                this.state = {
                    userInput: "你妹",
                    userCheck: true,
                }
            }

            clickHandler = () => {
                console.log(this.refs.ref1.value,this.state.userInput);
                console.log(this.refs.ref2.value);
                console.log(this.refs.ref3.value);
            }

            render() {
                return (
                    <div>
                        <div>state:{JSON.stringify(this.state)}</div>

                        {/* 通过字符串获取DOM */}
                        <input type="text" ref="ref1" defaultValue={this.state.userInput} /><br />

                        <textarea type="text" ref="ref2" defaultValue={this.state.userInput}></textarea><br />

                        <input type="checkbox" ref="ref3" defaultChecked={this.state.userCheck} /><br />

                        <button onClick={this.clickHandler}>获取用户输入</button>

                        <button onClick={() => {
                            this.setState(
                                {
                                    userInput: "我妹"+new Date(),
                                    userCheck: !this.state.userCheck
                                },
                                ()=>{
                                    this.refs.ref1.value = this.state.userInput
                                    this.refs.ref2.value = this.state.userInput
                                    this.refs.ref3.checked = this.state.userCheck
                                }
                            )
                        }}>修改state</button>
                        <br />
                    </div>
                )
            }
        }

        ReactDOM.render(<MyCom />, document.getElementById('root'))
    </script>
</body>

</html>